package com.baozhun.mall.common.widget.customview.filter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import com.baozhun.mall.common.R
import com.baozhun.mall.common.model.bean.FilterOptionItem
import com.zhy.view.flowlayout.FlowLayout
import com.zhy.view.flowlayout.TagAdapter

/**
 * @Title：
 * @Description：
 * @Author：xing.luo
 * @Since：2022/11/12
 * @Version：1.0.0
 */
class SizeFilterAdapter(data: List<FilterOptionItem>, val context : Context) : TagAdapter<FilterOptionItem>(data) {

    override fun getView(parent: FlowLayout?, position: Int, t: FilterOptionItem?): View {
        val root = LayoutInflater.from(context).inflate(R.layout.view_filter_tag_size, null) as RelativeLayout
        val textView = root.findViewById(R.id.size_tv) as TextView
        val imageView = root.findViewById(R.id.size_iv) as ImageView
        root.tag = t
        if (t?.sold_out == true) {
            imageView.visibility = View.VISIBLE
            textView.setTextColor(context.getColor(com.baozhun.mall.res.R.color.color_CCC))
            root.isClickable = false
            root.isFocusable = false
        } else {
            imageView.visibility = View.INVISIBLE
            textView.setTextColor(context.getColor(com.baozhun.mall.res.R.color.black))
        }
        textView.text = t?.name
        return root
    }
}